Ext.define('AM.controller.deptController',{
	extend:'Ext.app.Controller',
	init:function(){
		this.control({
			"deptTree button[id=allopen]":{
				click:function(o){
					var tree = o.ownerCt.ownerCt;
					tree.expandAll();
				}
			},
			"deptTree button[id=allclose]":{
				click:function(o){
					var tree = o.ownerCt.ownerCt;
					tree.collapseAll();
				}
			},
			"deptTree button[id=add]":{
				click:function(o){
					var tree = o.ownerCt.ownerCt;
					var nodes = tree.getChecked();
					if(nodes.length == 1){
						var node = nodes[0];
						node.appendChild({
							text:'XXX',
							id:'0101',
							checked:false,
							leaf:true
						});
					}else{
						alert("请选择一个节点");
					}
				}
			},
			'deptTree':{
				
				checkchange:function(node,checked,options){
					if(node.data.leaf == false){//如果不是叶子
						if(checked){
							node.expand();//打开节点
							node.eachChild(function(n){//遍历子节点
								n.data.checked = true;
								n.updateInfo({checked:true});
							});
						}else{
							node.eachChild(function(n){
								n.data.checked = false;
								n.updateInfo({checked:false});
							});
						}
					}else{
						if(!checked){
							node.parentNode.data.checked = false;
							node.parentNode.updateInfo({checked:false});
						}
					}
				},
				itemclick:function(tree,record,item,index,e,options){
					//alert(record.get('id'));
				}
			}
		});
	},
	views:['deptView'],
	stores:[],
	models:[]
});